#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc_c.h>
#include <opencv2/imgproc/imgproc.hpp>
#include "ContactManager.h"

int main()
{
	try
	{
		ContactManager cm(true);

		cv::Mat imgBackground = cv::imread("1.jpg");
		cv::Mat imgCurrent = cv::imread("2.jpg");
		cv::Mat imgWorkingA;
		cv::Mat imgWorkingB;
		//cv::VideoCapture test("mt_camera_raw.AVI");
		cv::VideoCapture test(CV_CAP_ANY);
		if(!test.isOpened())
			return 1;
		test.grab();
		test.retrieve(imgCurrent);
		imgBackground = imgCurrent.clone();
		cv::cvtColor(imgBackground, imgBackground, CV_RGB2GRAY);
		cm.init(imgBackground);

		int frame = 0;
		//double fps = test.get(CV_CAP_PROP_FPS);
		while(test.grab())
		{
			cv::waitKey(1);
			test.retrieve(imgCurrent);
			cv::cvtColor(imgCurrent, imgCurrent, CV_RGB2GRAY);
			/*
			frame++;
			if(frame < 50) {
				continue;
			}
			*/
			cm.update(imgCurrent);
			/*
			if(frame % 10 == 0)
				std::cout << "frame: " << frame << std::endl;;
			*/
		}
	}
	catch(cv::Exception& e) {
		std::cout << e.msg << std::endl;
		cv::waitKey();
	}
	return 0;
}